<?php
/**
 * Description of Table
 *
 * @author AndyLowe
 */
class FuseDriver_Table extends Zend_Db_Table_Abstract {

    protected $_dbAdapter;
    protected $_dbConfig;

    public function __construct($config = array()) {
        if (!isset($config['db'])) {
            $config["db"] = $this->getDbAdapter();
        }
        parent::__construct($config);
    }

    public function setDbAdapter(Zend_Db_Adapter_Abstract $dbAdapter) {
        $this->_dbAdapter = $dbAdapter;
        return $this;
    }

    public function getDbAdapter() {
        if (is_null($this->_dbAdapter)) {
            $dbAdapter = Zend_Db::factory($this->getDbConfig()->database);
            $this->setDbAdapter($dbAdapter);
        }
        return $this->_dbAdapter;
    }

    public function setDbConfig(Zend_Config $dbConfig) {
        $this->_dbConfig = $dbConfig;
        return $this;
    }

    public function getDbConfig() {
        if (is_null($this->_dbAdapter)) {
            $dbConfig = new Zend_Config_Ini(APPLICATION_PATH."/configs/database.ini", APPLICATION_ENV);
            $this->setDbConfig($dbConfig);
        }
        return $this->_dbConfig;
    }
    
    public function setName($name)
    {
        $this->_name = $name;
        return $this;
    }
    
    public function getName()
    {
        return $this->_name;
    }
}